#include "httpfactory.h"
#include <stdlib.h>
#include <arpa/inet.h>

#include "httpform.h"
#include "cpputils.h"
#include <iostream>

using namespace std;

const string name("name");
const string namevalue("namevalue");
const string filename("filename");
const string filepath("filepath");

void HttpSocket::run()
{

    string respbody("{}");
    string httpresp("HTTP/1.1 200 OK\r\n");
    httpresp += "Server: Apache-Coyote/1.1\r\n";
    httpresp += "Content-Type: application/json; charset=utf-8\r\n";
    httpresp += "Content-Length: " + int2a(respbody.length()) + "\r\n";
    httpresp += "\r\n";
    httpresp += respbody;

    HttpForm form;
    form.recv(m_fd,"./");
    form.noblock_send(m_fd,httpresp.c_str(),httpresp.length());

    map<string,string>& files = form.files();
    map<string,string>& fields= form.fields();

    map<string,string>::iterator it;
    for( it = fields.begin(); it != fields.end(); ++it)
        cout<<it->first<<":111"<<it->second<<"|"<<endl;
    for( it = files.begin(); it != files.end(); ++it)
        cout<<it->first<<":"<<it->second<<endl;
}




